package com.briup.day16;
import  static com.briup.day16.CustomerExceptionStatus.USERNAME_IS_NOT_EMPTY;

//import static com.briup.day16.CustomerConstants.LoginStatus.USERNAME_IS_NOT_EMPTY;

//import static com.briup.day16.CustomerConstants.RegisterStatus.USERNAME_IS_NOT_EMPTY;

/**
 * 使用异常改造代码。
 * 1.自定义异常，描述登录异常问题
 * throw new XXXException   替换掉  return语句
 *
 * @author lining
 * @date 2024/1/28 11:14
 */
public class TestLogin {
    public void login(LoginUser user){
        if(user.getUsername() == null){
//            throw new CustomerException(USERNAME_IS_NOT_EMPTY);//独立枚举类
//            throw new CustomerException(USERNAME_IS_NOT_EMPTY);//静态内部类
//            throw new CustomerException();
            throw new CustomerException(USERNAME_IS_NOT_EMPTY.getMsg());//枚举类（内部类）
        }

        if (user.getPassword() == null) {
            throw new CustomerException(1);
        }
        System.out.println(user.getUsername()+" 登录成功");
    }

    //实现 注册功能.使用信息被封装到一个类中
    public void register(RegisterUser user){
        if(user.getUsername() == null){
            throw new CustomerException(2);
        }
        if (user.getPassword() == null){
            throw new CustomerException(1);
        }
        System.out.println(user.getUsername()+" 注册成功");
    }
    //查询操作
    public void findByName(String username){
        if(username == null){
            throw new  CustomerException(USERNAME_IS_NOT_EMPTY);
        }

        System.out.println(username+"的个人信息是xxxx");
    }

    public static void main(String[] args) {
        TestLogin t = new TestLogin();
//        t.login(new LoginUser("jack","123456"));
       // t.login(new LoginUser(null,"123456"));
        RegisterUser registerUser = new RegisterUser(null, "123456",
                                        "jack@briup.com", "www.baidu.com/a.png",
                                        "13600000000");
        t.register(registerUser);
    }
}
